package com.jiangxiaofei.citycloud.activity.recruit;

import android.Manifest;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.InfoWindow;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.district.DistrictSearch;
import com.baidu.mapapi.search.district.DistrictSearchOption;
import com.bigkoo.pickerview.OptionsPickerView;
import com.blankj.utilcode.util.EmptyUtils;
import com.bumptech.glide.Glide;
import com.jiangxiaofei.citycloud.R;
import com.jiangxiaofei.citycloud.activity.user.LoginAcitivity;
import com.jiangxiaofei.citycloud.activity.user.MeRealInfoActivity;
import com.jiangxiaofei.citycloud.base.BaseActivity;
import com.jiangxiaofei.citycloud.bean.MapWorkBean;
import com.jiangxiaofei.citycloud.bean.MapWorkerBean;
import com.jiangxiaofei.citycloud.bean.WorkLabelBean;
import com.jiangxiaofei.citycloud.constants.Constants;
import com.jiangxiaofei.citycloud.constants.IntConstants;
import com.jiangxiaofei.citycloud.constants.StringConstants;
import com.jiangxiaofei.citycloud.event.RefreshMessage;
import com.jiangxiaofei.citycloud.mvp.RecruitConstant;
import com.jiangxiaofei.citycloud.mvp.RecruitPersenter;
import com.jiangxiaofei.citycloud.service.LocationService;
import com.jiangxiaofei.citycloud.view.IOSAlertDialog;
import com.thinkcool.circletextimageview.CircleTextImageView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import pub.devrel.easypermissions.EasyPermissions;

import static com.baidu.mapapi.map.MyLocationConfiguration.LocationMode;
import static com.baidu.mapapi.map.MyLocationConfiguration.LocationMode.NORMAL;

/**
 * Created by JiangXFei on 2017/8/10.
 * 招工主页  地图页面
 */

public class RecruitMapAcitivity extends BaseActivity implements SensorEventListener,
        EasyPermissions.PermissionCallbacks, View.OnClickListener,
        RecruitConstant.WorkLabelView, RecruitConstant.GetWorkerView,
        RecruitConstant.GetWorkView {
    @InjectView(R.id.map_mapv_show)
    MapView mapMapvShow;
    @InjectView(R.id.map_img_mtype)
    ImageView imgMtype;
    @InjectView(R.id.recruit_rb_do_work)
    RadioButton tvDoWork;
    @InjectView(R.id.recruit_rb_find_work)
    RadioButton tvFindWork;
    @InjectView(R.id.img_left_back)
    ImageView imgLeftBack;
    @InjectView(R.id.img_right_menu)
    ImageView imgRightMenu;
    @InjectView(R.id.recruit_circle_img_publish)
    CircleTextImageView recruitCircleImgPublish;
    private TextView tvMe, tvDo, tvFind;
    private BaiduMap mBaiduMap;
    private LocationMode
            mCurrentMode;
    private LocationClient mLocClient;
    String[] permissions = {Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_PHONE_STATE};
    public BDLocationListener myListener = new MyLocationListenner();
    private BitmapDescriptor mCurrentMarker;
    private SensorManager mSensorManager;
    private MapStatus.Builder builder;
    private LatLng ll;
    // 是否首次定位
    boolean isFirstLoc = true;
    private Double lastX = 0.0;
    private int mCurrentDirection = 0;
    private double mCurrentLat = 0.0;
    private double mCurrentLon = 0.0;
    private float mCurrentAccracy;
    private MyLocationData locData;
    private List<MapWorkBean> workList = new ArrayList<>();
    private List<MapWorkerBean> workerList = new ArrayList<>();
    private List<String> typeList;
    private int code = IntConstants.DOWORK;
    PopupWindow alertPopupView;
    private boolean isPopupShow;
    private RecruitConstant.WorkLabelPersenter workLabelPersenter;
    private RecruitConstant.GetWorkPersenter getWorkPersenter;
    private RecruitConstant.GetWorkerPersenter getWorkerPersenter;
    private List<WorkLabelBean> labelBeanList;
    private int role = 0;
    private TextView tvMapContent;

    @Override
    protected void initView(Bundle savedInstanceState) {
        mActivity = this;
        mContext = this;
        setContentView(R.layout.activity_recruit_map_layout);
        ButterKnife.inject(this);
        workLabelPersenter = new RecruitPersenter(mContext, (RecruitConstant.WorkLabelView) mActivity);
        getWorkPersenter = new RecruitPersenter(mContext, (RecruitConstant.GetWorkView) mActivity);
        getWorkerPersenter = new RecruitPersenter(mContext, (RecruitConstant.GetWorkerView) mActivity);
        typeList = new ArrayList<>();
        workLabelPersenter.getWorkLabel();
        Intent intent = getIntent();
        role = intent.getIntExtra(StringConstants.ROLE, 0);
        code = intent.getIntExtra(StringConstants.CODE, IntConstants.DOWORK);
        if (EasyPermissions.hasPermissions(this, permissions)) {
            initMap();
            initShowView();
            if (code == IntConstants.DOWORK) {
                getWorkPersenter.getWork();
                tvDoWork.setChecked(true);
                tvFindWork.setTextColor(Color.WHITE);
                tvDoWork.setTextColor(getResources().getColor(R.color.maintab_text_selected_color));
            } else {
                tvFindWork.setChecked(true);
                tvDoWork.setTextColor(Color.WHITE);
                tvFindWork.setTextColor(getResources().getColor(R.color.maintab_text_selected_color));
                getWorkerPersenter.getWorker();
            }
        } else {
            EasyPermissions.requestPermissions(this, "使用此功能需要提供您的位置权限。",
                    200, permissions);
        }
        initPopup();
        EventBus.getDefault().register(this);

        if (EmptyUtils.isNotEmpty(Constants.userInfo) && Constants.userInfo.getWorkintro().equals("1")) {
            recruitCircleImgPublish.setText("查看求职");
        } else {
            recruitCircleImgPublish.setText("发布求职");
        }
    }


    //初始化popupwindow
    private void initPopup() {
        alertPopupView = new PopupWindow();
        View view = LayoutInflater.from(mContext).inflate(R.layout.popup_alert_recruit_menu, null);
        alertPopupView.setContentView(view);
        alertPopupView.setWidth(DrawerLayout.LayoutParams.WRAP_CONTENT);
        alertPopupView.setHeight(DrawerLayout.LayoutParams.WRAP_CONTENT);
//        alertPopupView.setTouchable(true);
        alertPopupView.setFocusable(false);
        alertPopupView.setBackgroundDrawable(new ColorDrawable(0x00000000));
        isPopupShow = true;
        //我的信息
        tvMe = view.findViewById(R.id.popup_tv_me);
        //找工作
        tvDo = view.findViewById(R.id.popup_tv_do);
        //招工作
        tvFind = view.findViewById(R.id.popup_tv_find);
        tvMe.setOnClickListener(this);
        tvDo.setOnClickListener(this);
        tvFind.setOnClickListener(this);

    }

    //初始化螺旋仪
    private void initShowView() {
        // 获取传感器管理服务
        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    }

    /**
     * 初始化地图层
     */
    private void initMap() {
        //设置地图放大缩小按钮
        mapMapvShow.showZoomControls(false);
        mBaiduMap = mapMapvShow.getMap();
        //设置为普通模式的地图
        mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
        mCurrentMode = NORMAL;
        mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(
                mCurrentMode, true, null));
        // 开启定位图层
        mBaiduMap.setMyLocationEnabled(true);
        //定位用到的一个类
        mLocClient = new LocationClient(this);
        //注册监听
        mLocClient.registerLocationListener(myListener);

        ///LocationClientOption类用来设置定位SDK的定位方式，
        LocationClientOption option = new LocationService(mContext).getDefaultLocationClientOption();

        mLocClient.setLocOption(option);
        mLocClient.start();
        DistrictSearch mDistrictSearch = DistrictSearch.newInstance();
        DistrictSearchOption districtSearchOption = new DistrictSearchOption();
        if (Constants.bdLocation != null) {
            districtSearchOption.cityName(Constants.bdLocation.getCity());//检索城市名称
        } else {
            //检索城市名称
            districtSearchOption.cityName("青岛市");
        }
//        districtSearchOption.districtName(districtStr);//检索的区县名称
        //请求行政区数据
        mDistrictSearch.searchDistrict(districtSearchOption);
        mBaiduMap.setOnMapClickListener(new BaiduMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng latLng) {
                mBaiduMap.hideInfoWindow();
            }

            @Override
            public boolean onMapPoiClick(MapPoi mapPoi) {
                return false;
            }
        });
    }


    //类别选择弹出框
    public void showPickerViewType(final int typeCode) {
        String typeString = typeCode == IntConstants.DOWORK ? "我要干活" : "我需劳务";
        OptionsPickerView optionsPickerView = new OptionsPickerView.Builder(mContext, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                for (int i = 0; i < Constants.workLabelList.size(); i++) {
                    if (typeList.get(options1).equals(labelBeanList.get(i).getName())) {
                        role = i;
                    }
                }
                if (typeCode == IntConstants.DOWORK) {
                    getWorkPersenter.getWork();
                } else if (typeCode == IntConstants.FINDWORK) {
                    getWorkerPersenter.getWorker();
                }
            }
        }).setTitleText(typeString)
                .setDividerColor(Color.BLACK)
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(20)
                .setOutSideCancelable(false)// default is true
                .build();
        optionsPickerView.setPicker(typeList);
        optionsPickerView.show();
    }

    //工作坐标点
    private void initWorkMap() {
//        initMarkerBit();
        mCurrentMarker = BitmapDescriptorFactory
                .fromResource(R.drawable.ic_find_worker);
        OverlayOptions overlayOptions = null;
        LatLng latLng = null;
        Marker marker = null;
        for (MapWorkBean info : workList) {
            // 位置
            latLng = new LatLng(Double.valueOf(info.getLat()), Double.valueOf(info.getLog()));
            // 图标
            overlayOptions = new MarkerOptions().position(latLng)
                    .icon(mCurrentMarker).zIndex(5);
            marker = (Marker) (mBaiduMap.addOverlay(overlayOptions));
            Bundle bundle = new Bundle();
            bundle.putParcelable("work", info);
            marker.setExtraInfo(bundle);

        }
        mBaiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                //获得marker中的数据
                if (code == IntConstants.DOWORK) {
                    MapWorkBean info = (MapWorkBean) marker.getExtraInfo().get("work");
                    // 创建InfoWindow
                    InfoWindow mInfoWindow = new InfoWindow(
                            popupView(info.getDescription(), Integer.valueOf(info.getId())), marker.getPosition(), -80);
                    // 显示InfoWindow
                    mBaiduMap.showInfoWindow(mInfoWindow);
                }
                return true;
            }
        });
    }

    //工人坐标点
    private void initWokerMap() {
        mCurrentMarker = BitmapDescriptorFactory
                .fromResource(R.drawable.ic_other_woker);
        OverlayOptions overlayOptions = null;
        LatLng latLng = null;
        Marker marker = null;
        for (MapWorkerBean info : workerList) {
            // 位置
            latLng = new LatLng(Double.valueOf(info.getLat()), Double.valueOf(info.getLog()));
            // 图标
            overlayOptions = new MarkerOptions().position(latLng)
                    .icon(mCurrentMarker).zIndex(5);
            marker = (Marker) (mBaiduMap.addOverlay(overlayOptions));
            Bundle bundle = new Bundle();
            bundle.putParcelable("worker", info);
            marker.setExtraInfo(bundle);
        }
        mBaiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                //获得marker中的数据
                if (code == IntConstants.FINDWORK) {
                    final MapWorkerBean info = (MapWorkerBean) marker.getExtraInfo().get("worker");
                    if (EmptyUtils.isNotEmpty(info)) {
                        // 创建InfoWindow
                        InfoWindow mInfoWindow = new InfoWindow(
                                popupView(info.getIntroduce(), Integer.valueOf(info.getUserid())), marker.getPosition(), -80);

                        // 显示InfoWindow
                        mBaiduMap.showInfoWindow(mInfoWindow);
                    }
                }
                return true;
            }
        });
    }

    View popupView(String str, final int id) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.popup_map_content, null);
        tvMapContent = view.findViewById(R.id.popup_tv_content);
        tvMapContent.setText(str);
        tvMapContent.setOnClickListener(view1 -> {
            Intent intent;
            if (code == IntConstants.DOWORK) {
                intent = new Intent(mContext, RecruitFindWorkInfoActivity.class);
                intent.putExtra(StringConstants.WORKID, id + "");
                startActivity(intent);
            } else if (code == IntConstants.FINDWORK) {
                intent = new Intent(mContext, RecruitDoWorkInfoactivity.class);
                intent.putExtra(StringConstants.USERID, id);
                startActivity(intent);
            }
        });
        return view;
    }


    //设置头部按钮点击事件
    @Override
    protected void setListener() {
    }

    //设置头部信息
    @Override
    protected void processLogic(Bundle savedInstanceState) {
    }

    @OnClick({R.id.recruit_rb_do_work, R.id.recruit_rb_find_work,
            R.id.img_left_back, R.id.img_right_menu, R.id.recruit_circle_img_publish})
    public void OnClick(View v) {
        switch (v.getId()) {
            case R.id.recruit_rb_do_work:
                //我要干活
                showPickerViewType(IntConstants.DOWORK);
                code = IntConstants.DOWORK;
                tvFindWork.setTextColor(Color.WHITE);
                tvDoWork.setTextColor(getResources().getColor(R.color.maintab_text_selected_color));
                recruitCircleImgPublish.setText("发布求职");
                break;
            case R.id.recruit_rb_find_work:
                //点击我需劳务
                code = IntConstants.FINDWORK;
                showPickerViewType(IntConstants.FINDWORK);
                tvDoWork.setTextColor(Color.WHITE);
                tvFindWork.setTextColor(getResources().getColor(R.color.maintab_text_selected_color));
                recruitCircleImgPublish.setText("发布劳务");
                break;
            case R.id.img_left_back:
                //返回
                this.finish();
                break;
            case R.id.img_right_menu:
                //菜单按钮的点击事件
                if (EmptyUtils.isEmpty(Constants.userInfo)) {
                    startActivity(new Intent(mContext, LoginAcitivity.class));
                } else if (isPopupShow) {
                    alertPopupView.dismiss();
                    isPopupShow = false;
                } else {
                    alertPopupView.showAsDropDown(imgRightMenu);
                    isPopupShow = true;
                }
                break;
            case R.id.recruit_circle_img_publish:
                //发布信息按钮
                if (code == IntConstants.FINDWORK) {
                    //发布劳务
                    if (EmptyUtils.isEmpty(Constants.userInfo)) {
                        startActivity(new Intent(this, LoginAcitivity.class));
                    } else {
                        if (Constants.userInfo.getRealid().equals("1")) {
                            startActivity(new Intent(this, RecruitFindWorkPublishActivity.class));
                        } else {
                            Toast.makeText(mContext, "您还未实名认证，请下填写您的实名信息", Toast.LENGTH_SHORT).show();
                            startActivity(new Intent(this, MeRealInfoActivity.class));
                        }
                    }
                } else if (code == IntConstants.DOWORK) {
                    //发布干活信息
                    if (EmptyUtils.isEmpty(Constants.userInfo)) {
                        startActivity(new Intent(this, LoginAcitivity.class));
                    } else if (EmptyUtils.isNotEmpty(Constants.userInfo)) {
                        if (Constants.userInfo.getWorkintro().equals("1")) {
                            Intent intent = new Intent(this, RecruitDoWorkInfoactivity.class);
                            intent.putExtra(StringConstants.INTENTTYPE, StringConstants.MEINFO);
                            intent.putExtra(StringConstants.USERID, Constants.userId);
                            startActivity(intent);
                        } else if (Constants.userInfo.getRealid().equals("1")) {
                            startActivity(new Intent(this, RecruitDoWorkPublishAcitivty.class));
                        } else {
                            Toast.makeText(mContext, "您还未实名认证，请填写您的实名信息", Toast.LENGTH_SHORT).show();
                            startActivity(new Intent(this, MeRealInfoActivity.class));
                        }
                    }
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.popup_tv_do:
                //找工信息
                Intent intent = new Intent(mContext, RecruitDoWorkInfoactivity.class);
                intent.putExtra(StringConstants.INTENTTYPE, StringConstants.MEINFO);
                startActivity(intent);
                alertPopupView.dismiss();
                break;
            case R.id.popup_tv_me:
                //我的信息
                Intent intent1 = new Intent(mContext, MeRealInfoActivity.class);
                startActivity(intent1);
                alertPopupView.dismiss();
                break;
            case R.id.popup_tv_find:
                //招工信息
                startActivity(new Intent(mContext, RecruitFindWorkListActivity.class));
                alertPopupView.dismiss();
                break;
            default:
                break;
        }
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @OnClick({R.id.map_img_mtype})
    public void Onclick(View v) {
        switch (v.getId()) {
            case R.id.map_img_mtype:
                switch (mCurrentMode) {
                    case NORMAL:
                        Glide.with(mContext).load(R.drawable.alp).into(imgMtype);
                        mBaiduMap
                                .setMyLocationConfiguration(new MyLocationConfiguration(
                                        mCurrentMode, true, null));
                        builder.overlook(0);
                        builder.target(ll).zoom(15);
                        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
                        break;
                    default:
                        break;
                }
                break;
            default:
                break;
        }
    }


    @Override
    public void onSensorChanged(SensorEvent sensorEvent) {
//每次方向改变，重新给地图设置定位数据，用上一次onReceiveLocation得到的经纬度、精度
        double x = sensorEvent.values[SensorManager.DATA_X];
        if (Math.abs(x - lastX) > 1.0) {// 方向改变大于1度才设置，以免地图上的箭头转动过于频繁
            mCurrentDirection = (int) x;
            locData = new MyLocationData.Builder().accuracy(mCurrentAccracy)
                    // 此处设置开发者获取到的方向信息，顺时针0-360
                    .direction(mCurrentDirection).latitude(mCurrentLat).longitude(mCurrentLon).build();

            mBaiduMap.setMyLocationData(locData);

        }
        lastX = x;
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int i) {

    }

    //权限start
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        // Forward results to EasyPermissions
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

    @Override
    public void onPermissionsGranted(int requestCode, List<String> perms) {
        if (perms.size() == this.permissions.length) {
            initMap();
            initShowView();
        }
    }

    @Override
    public void onPermissionsDenied(int requestCode, final List<String> perms) {
        for (int i = 0; i < perms.size(); i++) {
            if (perms.get(i).equals(Manifest.permission.ACCESS_COARSE_LOCATION)) {
                IOSAlertDialog dialog = new IOSAlertDialog(mContext);
                dialog.builder().setTitle("提示")
                        .setMsg("您需要提供获取位置权限才能使用此功能")
                        .setNegativeButton("取消", view -> mActivity.finish())
                        .setPositiveButton("确定", view -> EasyPermissions.requestPermissions(mActivity, "使用此功能需要提供您的位置权限。",
                                200, permissions)).show();
            }
        }
    }

    @Override
    public void setData(Object o) {
        typeList.clear();
        labelBeanList = (List<WorkLabelBean>) o;
        WorkLabelBean bean = new WorkLabelBean("全部", 0);
        labelBeanList.add(0, bean);
        Constants.workLabelList = labelBeanList;
        if (labelBeanList.size() != 0) {
            for (int i = 0; i < labelBeanList.size(); i++) {
                typeList.add(labelBeanList.get(i).getName());
            }
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void message(String str) {

    }

    @Override
    public void getWorkLabel() {

    }

    @Override
    public int getWorkerRole() {
        return role;
    }

    @Override
    public void onSuccessWorker(Object o) {
        mBaiduMap.clear();
        workerList.clear();
        workerList.addAll((List<MapWorkerBean>) o);
        initWokerMap();
    }

    @Override
    public void onNull() {
        mBaiduMap.clear();
    }

    @Override
    public int getWorkRole() {
        return role;
    }

    @Override
    public void onSuccessWork(Object o) {
        mBaiduMap.clear();
        workList.clear();
        workList.addAll((List<MapWorkBean>) o);
        initWorkMap();
    }

    //权限END

    public class MyLocationListenner implements BDLocationListener {

        @Override
        public void onReceiveLocation(BDLocation location) {
            // map view 销毁后不在处理新接收的位置
            if (location == null || mBaiduMap == null) {
                return;
            }
            mCurrentAccracy = location.getRadius();
            mCurrentLat = location.getLatitude();
            mCurrentLon = location.getLongitude();
            locData = new MyLocationData.Builder()
                    .accuracy(location.getRadius())
                    // 此处设置开发者获取到的方向信息，顺时针0-360
                    .direction(100).latitude(location.getLatitude())
                    .longitude(location.getLongitude()).build();
            mBaiduMap.setMyLocationData(locData);
            if (isFirstLoc) {
                isFirstLoc = false;
                ll = new LatLng(location.getLatitude(),
                        location.getLongitude());
                builder = new MapStatus.Builder();
                builder.target(ll).zoom(15);
                mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
            }
        }

        @Override
        public void onConnectHotSpotMessage(String s, int i) {

        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，实现地图生命周期管理
        mapMapvShow.onDestroy();
        mSensorManager.unregisterListener(this);
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
        mapMapvShow.onResume();
        mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
                SensorManager.SENSOR_DELAY_UI);
    }


    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView. onPause ()，实现地图生命周期管理
        mapMapvShow.onPause();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refrensh(RefreshMessage message) {
        if (code == IntConstants.DOWORK) {
            getWorkPersenter.getWork();
        } else {
            getWorkerPersenter.getWorker();
        }
    }

}
